var box=$('#box')


function doCgStudentPassword() {
    $.ajax({
        url:'/student/cgStudentPassword',
        data:$('form').serialize(),
        success:()=>{
            alert("已修改")
        }
    })
}
function cgStudentPassword() {
    box.html(`
        <form onsubmit="return false">
            <div class="mb-3">
                <label for="account" class="form-label">账号</label>
                <input name="account" type="text" class="form-control" id="account" placeholder="请输入账号">
            </div>
            <div class="mb-3">
                <label for="oldPassword" class="form-label">旧密码</label>
                <input name="oldPassword" type="password" class="form-control" id="oldPassword" placeholder="请输入旧密码">
            </div>
            <div class="mb-3">
                <label for="newPassword" class="form-label">新密码</label>
                <input name="newPassword" type="password" class="form-control" id="newPassword" placeholder="请输入新密码">
            </div>
            <button type="button" class="btn btn-success" onclick="doCgStudentPassword()">修改密码</button>
        </form>
    `)
}


function stuHisRecord() {
    $.ajax({
        url:"/student/stuHisRecord",
        success:function (res) {
            let tbody=``;
            for (let i=0;i<res.length;i++){
                tbody+=`
                    <tr>
                      <td><span class="fw-bold ms-1">${res[i].id}</span></td>
                      <td><span >${res[i].type}</span></td>
                      <td><span >${res[i].addr}</span></td>
                      <td><span >${res[i].beginTime}</span></td>
                      <td><span >${res[i].endTime}</span></td>
                      <td><span>${res[i].contact1}</span></td>
                      <td><span>${res[i].contact2}</span></td>
                `
            }
            box.html(`
                <table id="myProjectTable" class="table table-hover align-middle mb-0" style="width:100%">
                  <thead>
                    <tr>
                      <th>编号</th>
                      <th>类型</th>
                      <th>住址</th>
                      <th>假期开始时间</th>
                      <th>假期结束时间</th>
                      <th>紧急联系人一</th>
                      <th>紧急联系人二</th>
                    </tr>
                  </thead>
                  <tbody>
                    ${tbody}
                  </tbody>
                </table>
            `)
            console.log("获取到内容")
            console.log(res)
        }
    })
}
function stuSubmit() {
    $.ajax({
        url:'/student/stuSubmit',
        data:$('form').serialize(),
        success:function () {
            alert("已提交")
        }
    })
}
function fillRecord(id) {
    console.log("id:"+id)
    if (id==null){
        box.html("貌似当前没有发布去向~~~")
    }else {
        box.html(`
            <form onsubmit="return false">
                <input type="hidden" value="${id}" name="id">
                <div class="mb-3">
                    <label for="type" class="form-label">类型</label>
                    <select name="type" type="text" class="form-control" id="type">
                        <option>离校</option>
                        <option>不离校</option>
                    </select>
                </div>
                <div class="mb-3">
                    <label for="addr" class="form-label">地址</label>
                    <input name="addr" type="text" class="form-control" id="addr">
                </div>
                <div class="mb-3">
                    <label for="beginTime" class="form-label">离校时间</label>
                    <input name="beginTime" type="date" class="form-control" id="beginTime">
                </div>
                <div class="mb-3">
                    <label for="endTime" class="form-label">返校时间</label>
                    <input name="endTime" type="date" class="form-control" id="endTime">
                </div>
                <div class="mb-3">
                    <label for="contact1" class="form-label">联系人一</label>
                    <input name="contact1" type="text" class="form-control" id="contact1">
                </div>
                <div class="mb-3">
                    <label for="contact2" class="form-label">联系人二</label>
                    <input name="contact2" type="text" class="form-control" id="contact2">
                </div>
                <div class="mb-3">
                    <label for="traffic" class="form-label">交通方式</label>
                    <input name="traffic" type="text" class="form-control" id="traffic">
                </div>
                <button type="button" class="btn btn-success" onclick="stuSubmit()">提交表格</button>
            </form>
        `)
    }
}